/**
 * Created by oak on 14-8-3.
 */

function check(str,reg){
    var objExp=new RegExp(reg);
    if(objExp.test(str)==true){
        return true;
    }else{
        return false;
    }
}

status=false;

function chkreg(form,label){
    if(label=='account')
    {
        if(!check(form.account.value,/^[0-9A-Za-z_]{1,20}$/g))
        {
            check_account.innerHTML="登录名格式不正确！";
            form.account.style.backgroundColor="#F1B000";
            $('#check_account').slideDown('fast');
            return false;
        }
        form.account.style.backgroundColor="#FFFFFF";
        $('#check_account').slideUp('fast');
    }
    if( label=="all"){
        htmlobj=$.ajax({url:path+"/index.php/Profile/account?account="+form.account.value,async:false});
        if(htmlobj.responseText.match('true'))
        {
            window.parent.$.messager.alert('提示','该用户名已被注册！','error',function(){
                status=false;
                $("input[name='account']").focus();
                $("input[name='account']").css('background-color','#F1B000');
                check_account.style.display="none";
                return false;
            });
        }
        else status=true;

    }

    if(label=='password' || label=="all" || label=='password1'){
        if(!check(form.password.value,/^[0-9A-Za-z_]{6,10}$/g))
        {
            check_password.innerHTML="密码长度不正确！";
            form.password.style.backgroundColor="#F1B000";
            //check_password.style.display="block";
            $('#check_password').slideDown('fast');
            return false;
        }
        form.password.style.backgroundColor="#FFFFFF";
        check_password.style.display="none";
        if(form.password.value!=form.password1.value)
        {
            check_password.innerHTML="再次输入的密码不一致！";
            form.password1.style.backgroundColor="#F1B000";
            //check_password.style.display="block";
            $('#check_password').slideDown('fast');
            return false;
        }
        form.password1.style.backgroundColor="#FFFFFF";
        //check_password.style.display="none";
        $('#check_password').slideUp();
    }

    if(label=='name' || label=="all"){
        if(!check(form.name.value,/^[\w|\W]{1,20}$/g))
        {
            check_name.innerHTML="姓名长度不正确！";
            form.name.style.backgroundColor="#F1B000";
            //check_name.style.display="block";
            $('#check_name').slideDown('fast');
            return false;
        }
        form.name.style.backgroundColor="#FFFFFF";
        //check_name.style.display="none";
        $('#check_name').slideUp('fast');
    }

    if(label=='id' || label=="all"){
        if(!check(form.id.value,/^(\d{17}[\d|x|X]{1})?$/g))
        {
            check_id.innerHTML="身份证号不正确！";
            form.id.style.backgroundColor="#F1B000";
            //check_id.style.display="block";
            $('#check_id').slideDown('fast');
            return false;
        }
        form.id.style.backgroundColor="#FFFFFF";
        //check_id.style.display="none";
        $('#check_id').slideUp('fast');
    }

    if(label=='qq' || label=="all"){
        if(!check(form.qq.value,/^(\d{5,11})?$/g))
        {
            check_qq.innerHTML="QQ号格式不正确！";
            form.qq.style.backgroundColor="#F1B000";
            //check_qq.style.display="block";
            $('#check_qq').slideDown('fast');
            return false;
        }
        form.qq.style.backgroundColor="#FFFFFF";
        //check_qq.style.display="none";
        $('#check_qq').slideUp('fast');
    }


    if(label=='email' || label=="all"){
        if(!check(form.email.value,/^(\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)?$/))
        {
            check_email.innerHTML="Email格式不正确！";
            form.email.style.backgroundColor="#F1B000";
            //check_email.style.display="block";
            $('#check_email').slideDown('fast');
            return false;
        }
        form.email.style.backgroundColor="#FFFFFF";
        //check_email.style.display="none";
        $('#check_email').slideUp('fast');
    }

    if(label=='contacts' || label=="all"){
        if(!check(form.contacts.value,/^(1\d{10})?$/))
        {
            check_contacts.innerHTML="手机号格式不正确！";
            form.contacts.style.backgroundColor="#F1B000";
            //check_contacts.style.display="block";
            $('#check_contacts').slideDown('fast');
            return false;
        }
        form.contacts.style.backgroundColor="#FFFFFF";
        $('#check_contacts').slideUp('fast');
        //check_contacts.style.display="none";
    }
    if(status=='false')
        return false;
}

function myformatter(date){
    var y = date.getFullYear();
    var m = date.getMonth()+1;
    var d = date.getDate();
    return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
}
function myparser(s){
    if (!s) return new Date();
    var ss = (s.split('-'));
    var y = parseInt(ss[0],10);
    var m = parseInt(ss[1],10);
    var d = parseInt(ss[2],10);
    if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
        return new Date(y,m-1,d);
    } else {
        return new Date();
    }
}


